<!--
 * @Description: 修改批次名称弹窗
 * @Author: liyujie
 * @Date: 2021/2/23
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/2/23
-->

<template>
    <section class="wrapper">
        <el-dialog
            :title="title"
            width="580px"
            :visible.sync="dialogVisible"
            :close-on-click-modal="false"
            @close="handleClose"
        >
            <el-form
                class="base-info contract"
                :model="ruleForm"
                :rules="rules"
                ref="ruleForm"
                label-position="right"
                label-width="124px"
            >
                <el-form-item
                    label="批次组名称"
                    prop="series_title"
                >
                    <el-input
                        v-model="ruleForm.series_title"
                        size="medium"
                        clearable
                        style="width: 360px"
                    />
                </el-form-item>
            </el-form>
            <div class="btn">
                <el-button
                    size="medium"
                    style="width: 120px;margin-right: 32px"
                    @click="dialogVisible = false"
                >
                    取消
                </el-button>
                <el-button
                    size="medium"
                    type="primary"
                    style="width: 120px"
                    :disabled="ruleForm.series_title === ''"
                    @click="handleSubmit"
                >
                    确认
                </el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
export default {
    name: "SeriesTitleEdit",
    data() {
        return {
            dialogVisible: false,
            title: '',
            ruleForm: {
                series_title: '',
            },
            rules: {
                series_title: [
                    {required: true, message: '请填写批次组名称', trigger: 'blur'}
                ],
            },
        };
    },
    mounted() {},
    methods: {
        /**
         * 显示弹窗
         * @param title
         * @param value
         */
        show(title, value = '') {
            this.ruleForm.series_title = value;
            this.title = title;
            this.dialogVisible = true;
        },

        /**
         * 提交
         */
        handleSubmit() {
            this.$refs.ruleForm.validate((valid) => {
                if(valid) {
                    this.$post('/student/room_series%5Ccheck_title_exist', {title: this.ruleForm.series_title}, resp => {
                        if (resp.code === 1) {
                            if(resp.data.result) {
                                this.$confirm('当前输入的新批次组名称在列表中已存在相同名称，是否继续保存?', '提示', {
                                    confirmButtonText: '保存',
                                    cancelButtonText: '取消',
                                    type: 'warning'
                                }).then(() => {
                                    this.dialogVisible = false;
                                    this.$emit('confirm', this.ruleForm.series_title);
                                }).catch(() => {});
                            } else {
                                this.dialogVisible = false;
                                this.$emit('confirm', this.ruleForm.series_title);
                            }
                        } else {
                            this.$notify({
                                title: '提示',
                                message: resp.msg,
                                type: 'warning',
                                duration: 2000
                            });
                        }
                    });
                }
            });
        },

        /**
         * 弹窗关闭 重置表单
         */
        handleClose() {
            this.ruleForm.series_title = '';
            this.$refs.ruleForm.clearValidate();
        },

    }
};
</script>

<style scoped lang="less">
.wrapper {
    .tips {
        color: #999999;
        font-size: 12px;
        margin-left: 12px;
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow: 0 1px 0 0 rgba(233, 233, 233, 1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;

        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .el-icon-close:before {
            color: rgb(194, 194, 194);
            font-size: 17px;
            font-weight: bold;
        }

        .el-dialog__headerbtn {
            top: 14px;
        }
    }

    /deep/ .el-dialog__body {
        padding: 48px 36px;
        max-height: 600px;
        overflow: auto;
        &::-webkit-scrollbar {
            width: 6px;
        }
    }
    .btn {
        text-align: center;
        margin-top: 36px;
    }
}
</style>
